package com.andy.blog.dal.service.impl;

import com.andy.blog.common.exception.BlogServiceException;
import com.andy.blog.common.reponse.BlogResultCode;
import com.andy.blog.common.utils.TransformUtils;
import com.andy.blog.dal.domain.HitokotoDO;
import com.andy.blog.dal.mapper.HitokotoMapper;
import com.andy.blog.dal.service.HitokotoDalService;
import com.andy.blog.dal.vo.HitokotoVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by andy on 2024/6/25 17:13
 **/
@Service
public class HitokotoDalServiceImpl implements HitokotoDalService {
    @Resource
    private HitokotoMapper hitokotoMapper;

    @Override
    public void insertHitokoto(HitokotoVO hitokotoVO) {
        HitokotoDO hitokotoDO = TransformUtils.transform(hitokotoVO, HitokotoDO.class);

        try {
            hitokotoMapper.insert(hitokotoDO);
        } catch (Exception e) {
            throw new BlogServiceException(BlogResultCode.BLOG_000100, e);
        }
    }

    @Override
    public HitokotoVO selectDataByRandom() {
        HitokotoDO hitokotoDO = hitokotoMapper.selectRandom();
        return TransformUtils.transform(hitokotoDO, HitokotoVO.class);
    }
}
